<style>
    .hidden {
        display: none;
    }
</style>
<div class="layui-form" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="menuName" value="{{ d.params.menuName || '' }}" lay-verify="menuName" autocomplete="off" class="layui-input">
            </script>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">英文名</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="engName" value="{{ d.params.engName || '' }}" lay-verify="engName" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">父级ID</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <select name="parentId" value="{{ d.params.parentId || '' }}" id="parentId" lay-verify="parentId" lay-search="">

                </select>

            </script>
        </div>
    </div>

    <script type="text/html" template>
        <input name="menuId" value="{{ d.params.menuId || '' }}" class="hidden">
    </script>

    <div class="btn-one">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>上传背景图</legend>
        </fieldset>
        <div class="layui-upload-drag" style="text-align: left;">
            <i class="layui-icon test3"></i>
            <p>点击上传背景图</p>
            <script type="text/html" template>
                <div class="{{d.params.menuId?'':'layui-hide'}}" id="uploadDemoView3">
                    <hr>
                    <img src="{{ d.params.bgImg || '' }}" style="max-width: 196px" />
                    <input class="hidden" name="bgImg" value="{{ d.params.bgImg || '' }}">
                </div>
            </script>
        </div>
    </div>
    <div class="btn-five" style="text-align: right;">
        <div class="layui-input-inline">
            <input type="button" id="okbtn" lay-submit lay-filter="LAY-user-front-submit" value="确认" class="layui-btn" style="margin-bottom: 30px;">
        </div>
    </div>
</div>

<script>
    layui.use('upload', function() {
        var $ = layui.jquery,
            setter = layui.setter,
            admin = layui.admin,
            upload = layui.upload;

        //获取子菜单
        getmenu()

        function getmenu() {
            //取值
            var arr = sessionStorage.getItem('categoryId');
            admin.req({
                url: setter.request.baseUrl + "/product/admin/menu",
                data: {
                    parentId: 4
                },
                type: "get",
                done: function(res) {
                    if (res.code == 0) {
                        var html = "",
                            html1 = "";
                        html1 = "<option value=''>请选择</option>"
                        for (let i = 0; i < res.list.length; i++) {
                            html += "<option value=" + res.list[i].menuId + ">" + res.list[i].menuName + "</option>"
                        }
                        $("select[name='parentId']").empty().append(html1 + html)
                        if (arr != "") {
                            $("select[name='parentId'] option[value=" + arr + "]").attr("selected", true)
                        }
                        layui.form.render('select')
                    }
                },
            });
        }
        //上传图片

        upload.render({
            elem: '.test3',
            url: setter.request.baseUrl + '/upload/admin/file',
            exts: 'jpg|png|jpeg',
            done: function(res) {
                layer.msg('上传成功');
                layui.$('#uploadDemoView3').removeClass('layui-hide').find('img').attr('src', res.data.src);
                $("input[name='registeNo']").val(res.data.src)
            }
        });

    });
</script>